package com.bac.bacplatform;

import java.util.List;

import com.bac.utils.LockPatternUtils;
import com.bac.utils.LockPatternView;
import com.bac.utils.LockPatternView.Cell;
import com.bac.utils.LockPatternView.DisplayMode;
import com.bac.utils.LockPatternView.OnPatternListener;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

public class LoginLockActivity extends BaseActivity {
	private LockPatternView lockPatternView;
	private LockPatternUtils lockPatternUtils;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login_lock);
		
		findViewById(R.id.lockOK_login).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				lockPatternUtils.clearLock();
				Intent intentToLogin = new Intent(LoginLockActivity.this,
						LoginActivity.class);
				startActivityIn(intentToLogin);
			}
		});
		
	}

	@Override
	public void init() {
		lockPatternView = (LockPatternView) findViewById(R.id.lpv_lock_login);
		lockPatternUtils = new LockPatternUtils(this);
		lockPatternView.setOnPatternListener(new OnPatternListener() {

			public void onPatternStart() {

			}

			public void onPatternDetected(final List<Cell> pattern) {
				int result = lockPatternUtils.checkPattern(pattern);
				if (result != 1) {
					lockPatternView.setDisplayMode(DisplayMode.Wrong);
//					Toast.makeText(LoginLockActivity.this, "密码错误",
//							Toast.LENGTH_LONG).show();
//					lockPatternView.clearPattern();
				} else {
//					Toast.makeText(LoginLockActivity.this, "密码正确",
//							Toast.LENGTH_LONG).show();
					Intent intentToMain = new Intent(LoginLockActivity.this,
							MainActivity.class);
					startActivityIn(intentToMain);
					finish();
				}
			}

			public void onPatternCleared() {

			}

			public void onPatternCellAdded(List<Cell> pattern) {

			}
		});
	}
}
